#include "StdAfx.h"
#include "Config.h"

/////////////////////////////////////////////////

Config::Config(void)
{
}

//-------------------------------------------------------------------------------------->

int Config::OpenFile(String^ path){
	if (System::IO::File::Exists(path)){
		reader = gcnew XmlTextReader(path);
		return 0;
	}
	else
	return -1;
}

//-------------------------------------------------------------------------------------->

array<String^>^ Config::ReadList(String^ blockName){
	
	array<String^>^ value;
	
	//XmlTextReader^ reader;
	//SQLiteConnection ^ connection = gcnew SQLiteConnection(String::Format("Data Source={0}; Version=3;", database));
	//connection->Open();
	//command->ExecuteNonQuery();
	
	//String^ query = "";
	value->Resize(value,0);
	if (reader->ReadToDescendant(blockName) ){
		while ( reader->Read() && reader->Name != blockName ) {
			if (reader->Name == "item") {
				
				value->Resize(value,value->Length+1);
				//Array::Resize(value,reader->AttributeCount);
				//Array::Resize(attribute_name,reader->AttributeCount);
				
				for (int i = 0; i < reader->AttributeCount; i++){
					value[value->Length-1] = reader->GetAttribute(i);
				}
		    }
	    }
		
     }
	//reader->Close();
	return value;
}

//-------------------------------------------------------------------------------------->
int Config::CloseFile(){
	reader->Close();
	return 0;
}
//-------------------------------------------------------------------------------------->
